/**
 * 
 */
package cn.jupiter.servlet;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import cn.jupiter.json.RestResource;

/**
 * @author Administrator
 *	解析url
 */
public class RestUrlParser {

	public static RestResource parserUrl(String url){
		
		if(url.endsWith("/")){
			RestResource r=new RestResource();
			r.setResouce(url.substring(url.lastIndexOf("/")+1));
			return r;
		}
		else{
			RestResource r=new RestResource();
			
			url=url.substring(url.indexOf("/rest")+6);
		
			if(url.indexOf("/")!=-1){
				r.setId(url.substring(url.lastIndexOf("/")+1));
				r.setResouce(url.substring(0,url.lastIndexOf("/")));
			}
			else{
				r.setResouce(url);
			}
			return r;
		}

	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
	//	Matcher m = Pattern.compile("[\u4e00-\u9fa5]").matcher("中午 is full of the linnet's wings");
	//	System.out.println(m.find());
		RestUrlParser p=new RestUrlParser();
		String url="http://localhost:8080/simpleJupiter/rest/user";
		//String url="http://localhost:8080/simpleJupiter/rest/mybean/40";
		
	
		System.out.println(p.parserUrl(url).getId());

		System.out.println(p.parserUrl(url).getResouce());
		
		
	}

}
